package com.careercup.question.id11146157;

public class Solution {
	private static class Node {
		private Node left, right;
		private int data;
		public Node(int data) {
			this.data = data;
		}
		public boolean isBST() {
			return inRange(Integer.MIN_VALUE, Integer.MAX_VALUE);
		}
		private boolean inRange(int min, int max) {
			if(data < min || data > max)
				return false;
			return (left == null || left.inRange(min, data)) && (right == null || right.inRange(data, max));
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		 Node n1 = new Node(1), n2 = new Node(2);
		 Node n3 = new Node(3), n4 = new Node(4);
		 Node n5 = new Node(5), n6 = new Node(6);
		 Node n7 = new Node(7), n8 = new Node(8);
		 Node n9 = new Node(9), n10 = new Node(10);
		 Node n11 = new Node(11), n12 = new Node(12);
		 Node n13 = new Node(13), n14 = new Node(14);
		 Node n15 = new Node(15);
		 n15.left = n13;
		 n15.right = n14;
		 n13.left = n9;
		 n13.right = n10;
		 n14.left = n11;
		 n14.right = n12;
		 n9.left = n1;
		 n9.right = n2;
		 n10.left = n3;
		 n10.right = n4;
		 n11.left = n5;
		 n11.right = n6;
		 n12.left = n7;
		 n12.right = n8;
		 System.out.println(n1.isBST());
	}
}
